﻿Imports BUS
Imports DTO

Public Class frmTHEMNHANVIEN

    Private Sub frmTHEMNHANVIEN_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DBNGKDataSet2.NHANVIEN' table. You can move, or remove it, as needed.

        LoadDSNV()
    End Sub

    Public Sub LoadDSNV()
        dgv_NV.DataSource = NhanVienBUS.LAYTATCA()
    End Sub

    Private Sub btn_them_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_them.Click
        If txt_diachi.Text <> "" And txt_sdt.Text <> "" And txt_TenNV.Text <> "" Then
            Dim nv As New NhanVienDTO()
            nv.TenNV = txt_TenNV.Text
            nv.SDT = txt_sdt.Text
            nv.DiaChi = txt_diachi.Text
            nv.NgayVaoLam = dtp_ngayvaplam.Value
            NhanVienBUS.THEM(nv)
            LoadDSNV()
            MessageBox.Show("Da Them Thanh Cong!")
        Else
            MessageBox.Show("Xin Nhap Day Du Thong Tin!", "Thông Báo")
        End If

    End Sub

    Private Sub btn_xoa_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

        LoadDSNV()
        MessageBox.Show("Da Xoa Thành Công")
    End Sub

    Private Sub btn_sua_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_sua.Click
        Dim dial = MessageBox.Show("Bạn Có Thực Sự Muốn Cập Nhập Nhân Viên Này?",
                                   "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If dial = DialogResult.Yes Then
            Dim nv As New NhanVienDTO
            nv.TenNV = txt_TenNV.Text
            nv.SDT = txt_sdt.Text
            nv.DiaChi = txt_diachi.Text
            nv.NgayVaoLam = dtp_ngayvaplam.Value
            nv.MaNV = dgv_NV.Rows(temp).Cells(0).Value
            NhanVienBUS.CAPNHAP(nv)
            LoadDSNV()
            MessageBox.Show("Da Cap Nhap Thanh Cong!")
        End If
       
    End Sub


    Private Sub btn_Nhaplai_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_Nhaplai.Click
        nhaplai()
    End Sub
    Private Sub nhaplai()
        txt_diachi.Text = ""
        txt_sdt.Text = ""
        txt_TenNV.Text = ""
        dtp_ngayvaplam.Text = ""

    End Sub

    Private Sub btn_thoat_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_thoat.Click
        Me.Close()
    End Sub


    Dim temp As Integer
    Private Sub dgv_NV_RowEnter(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv_NV.RowEnter
        temp = e.RowIndex
    End Sub

    Private Sub btn_xoa_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_xoa.Click
        Dim dial = MessageBox.Show("Bạn Có Thực Sự Muốn Xóa Nhân Viên Này?", "Hỏi", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
        If dial = DialogResult.Yes Then
            Dim nv As New NhanVienDTO()
            nv.MaNV = dgv_NV.Rows(temp).Cells(0).Value
            NhanVienBUS.XOA(nv.MaNV)
            LoadDSNV()
            MessageBox.Show("Da Xoa Thanh Cong!")
        End If
    End Sub
End Class